package com.code.util;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * redis工具类
 *
 * @author ww
 * @date 2018/9/8
 */
@Service
public class RedisUtil {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 根据key值,获取redis中的数据
     * Created by ww on 2018/8/9 14:32
     * @param key redis key值
     * @return key值
     */
    public String getRedisData(String key){
        ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
        return opsForValue.get(key);
    }
    /**
     * 根据key值,设置redis中的值
     * Created by ww on 2018/8/9 14:32
     * @param key redis key值
     * @return 设置结果
     */
    public boolean setRedisValue(String key, String value){
        ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
        opsForValue.set(key, value);
        return true;
    }
}

